<template>
  <div class="box">
    <el-card class="card">
      <div class="cn">
        <span class="lang">{{ locale == "zh" ? "cn" : "en" }}</span>
      </div>
      <div class="logo"><img src="@/assets/logo.png" alt="" /></div>
      <el-form :rules="rules" :model="loginForm" ref="loginForm">
        <el-form-item :label="$t('lang.account')" prop="account"
          ><el-input v-model="loginForm.account"></el-input
        ></el-form-item>
        <el-form-item :label="$t('lang.password')" prop="password"
          ><el-input v-model="loginForm.password" type="password"></el-input
        ></el-form-item>
        <el-form-item
          ><el-button type="primary" class="loginbtn" @click="submitForm">{{
            $t("lang.login")
          }}</el-button></el-form-item
        >
        <el-form-item
          ><el-button class="registbtn" plain type="primary">{{
            $t("lang.register")
          }}</el-button></el-form-item
        >
      </el-form>
    </el-card>
    <div class="footer">
      <div class="seed"></div>
      <div class="copyright">
        &copy; 2008-2021{{ $t("lang.compony") }}粤ICP备13058720号
      </div>
      <div>{{ $t("lang.privacy") }}</div>
      <div class="secure"></div>
      <el-select
        v-model="lang"
        :placeholder="$t('lang.lang')"
        @change="changeLang"
      >
        <el-option :label="$t('lang.cs')" value="zh"></el-option>
        <el-option :label="$t('lang.is')" value="en"></el-option>
      </el-select>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "loginView",
  data() {
    return {
      loginForm: {
        account: "",
        password: "",
      },
      lang: "",
      country: 1,
      rules: {
        account: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          {
            min: 3,
            max: 12,
            message: "长度在 3 到 12 个字符",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 8, message: "长度在 3 到 8 个字符", trigger: "blur" },
        ],
      },
    };
  },
  computed: {
    ...mapGetters(["locale"]),
  },
  methods: {
    changeLang() {
      this.$store.commit("SET_LANG", this.lang);
      this.$router.go(0);
    },
    submitForm() {
      this.$refs["loginForm"].validate((valid) => {
        if (valid) {
          this.$store.dispatch("LoginAction", this.loginForm);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  background: #ebeef2;
  height: 100%;
  width: 100%;
  overflow: hidden;
  .card {
    width: 380px;
    height: 500px;
    margin: 200px auto;
    position: relative;
    .loginbtn,
    .registbtn {
      width: 100%;
    }
    .cn {
      position: absolute;
      right: 0px;
      top: 0px;
      width: 0px;
      height: 0px;
      border: 40px solid transparent;
      border-top-color: blue;
      border-right-color: blue;
      .lang {
        color: #fff;
        font-size: 28px;
        position: absolute;
        width: 30px;
        height: 30px;
        right: -34px;
        top: -39px;
      }
    }
    .logo {
      width: 200px;
      height: 70px;
      text-align: center;
      margin-left: 80px;
      img {
        width: 100%;
      }
    }
  }
  .footer {
    width: 100%;
    height: 80px;
    background: #fff;
    position: fixed;
    bottom: 0;
    padding: 0px 250px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    box-sizing: border-box;
    .seed {
      height: 100%;
      width: 100px;
      background: url("@/assets/seeed.png") no-repeat 0;
      background-size: contain;
    }
    .secure {
      height: 100%;
      width: 100px;
      background: url("@/assets/mcafee.png") no-repeat 0;
      background-size: contain;
    }
    .copyright {
      height: 100%;
      width: 312px;
      font-size: 12px;
      line-height: 20px;
      margin-top: 50px;
    }
  }
}
</style>